package pattern14;

/**
 * p180
 * 备忘录模式
 * @author wdl
 */
public class MementoPattern {
    public static void main(String[] args) {
        //初始化发起者并设置初始化状态为On
        Originator originator=new Originator();
        originator.setState("On");
        originator.show();

        //创建管理者
        Caretaker caretaker=new Caretaker();
        //管理者保存备份
        caretaker.saveMemento(originator.createMemento());

        //设置新的状态
        originator.setState("Off");
        originator.show();

        //恢复备份
        originator.getStateFromMemento(caretaker.getMemento());
        originator.show();
    }
}
